import request from '@/utils/request';

/**
 * 门店列表分组列表 初始化
 */
export function storeInit() {
  return request({
    url:  '/merchant_backend/store_groups',
    method: 'GET'
  })
}
/**
 * 门店列表分组列表分页 初始化
 * @param {Number} page 分页页码
 */
export function storeGroupPage(page) {
  return request({
    url:  '/merchant_backend/store_groups',
    method: 'GET',
    params: { page }
  })
}

/**
 * 点击分组查询门店列表
 * @param {Number} id 分组id
 */
export function searchStores(id) {
  return request({
    url:  '/merchant_backend/store_groups/' + id + '/stores',
    method: 'GET'
  })
}

/**
 * 点击分组查询门店列表分页
 * @param {Number} id 分组id
 * @param {Number} page 分页id
 */
export function searchStoresPage(id, page) {
  return request({
    url:  '/merchant_backend/store_groups/' + id + '/stores',
    method: 'GET',
    params: { page }
  })
}

/**
 * 添加分组
 * @param {Object} name 分组名
 * @param {Array} stores 门店列表
 */
export function addGroup(name, stores) {
  const data = {
    name,
    stores
  }
  return request({
    url:  '/merchant_backend/store_groups',
    method: 'POST',
    data
  })
}

/**
 * 无分组门店查询
 * @return {JSON}
 */
export function handleGetStroeInit() {
  return request({
    url: '/merchant_backend/stores/un_group_stores',
    method: 'GET'
  })
}

/**
 * 无分组门店查询分页
 * @return {JSON}
 */
export function handleGetStroePage(page) {
  return request({
    url: '/merchant_backend/stores/un_group_stores',
    method: 'GET',
    params: { page }
  })
}

/**
 * 修改分组数据获取
 * @param {Number} id 分组id
 */
export function addGroupGetList(id) {
  return request({
    url:  '/merchant_backend/store_groups/' + id,
    method: 'GET'
  })
}

/**
 * 修改分组提交
 */
export function editGroupSub(id, name, stores) {
  const data = {
    id,
    name,
    stores
  }
  return request({
    url:  '/merchant_backend/store_groups',
    method: 'PUT',
    data
  })
}

/**
 * 添加门店
 * @param {Object} date 添加门店参数
 */
export function addStores(date) {
  const data = {
    store_number: date.storeNumber,
    store_name: date.storeName,
    store_area: date.storeArea,
    store_address: date.storeAddress,
    store_status: date.storeStatus,
    group_id: date.storeGroup
  }
  return request({
    url:  '/merchant_backend/stores',
    method: 'POST',
    data
  })
}

/**
 * 获取地区列表
 */
export function Address() {
  return request({
    url:  '/merchant_backend/getareas',
    method: 'GET'
  })
}

/**
 * 修改门店获取数据
 * @param {NUmber} id 门店id
 */
export function editStore(id) {
  return request({
    url:  '/merchant_backend/stores/' + id,
    method: 'GET'
  })
}

/**
 * 修改门店提交
 * @return {Object} 提交参数
 */
export function editStores(id, date) {
  const data = {
    store_number: date.editStoreId,
    store_name: date.editStoreName,
    store_area: date.editStoreCity,
    store_address: date.editStoreAddress,
    store_status: date.editStoreStatus,
    group_id: date.editStoreGroup
  }
  return  request({
    url:  'merchant_backend/stores/' + id,
    method: 'PUT',
    data
  })
}

/**
 * 门店删除
 * @param  {NUmber} id 门店id
 * @return {JSON}    返回json
 */
export function storeDele(id) {
  return request({
    url:  '/merchant_backend/stores/' + id,
    method: 'DELETE'
  })
}

/**
 * 店员列表初始化
 * @return {JSON} 返回json
 */
export function personInit() {
  return request({
    url:  '/merchant_backend/staffs',
    method: 'GET'
  })
}

/**
 * 店员列表查询
 * @param  {[Number]} store_id   [门店id]
 * @param  {[String]} staff_name [店员名称]
 * @return {[JSON]}            [返回json]
 */
export function searchPersonInit(store_id, staff_name) {
  return request({
    url:  '/merchant_backend/staffs',
    method: 'GET',
    params: { store_id, staff_name }
  })
}

/**
 * 店员列表分页
 * @param {Number} page 页码
 * @param {Object} date 参数
 */
export function pagePerson(page, date) {
  return request({
    url:  '/merchant_backend/staffs',
    method: 'GET',
    params: { page, staff_name: date.staff_name, store_id: date.store_id }
  })
}

/**
 * 添加店员
 * @param {Object} date 添加店员参数
 */
export function handleAddperson(date) {
  const data = {
    store_id: date.storeid,
    username: date.username,
    passwd: date.passwd,
    staff_name: date.staff_name,
    position: date.position,
    status: date.status
  }
  return request({
    url:  '/merchant_backend/staffs',
    method: 'POST',
    data
  })
}

/**
 * 店员删除
 * @param {Number} id 店员id
 */
export function handlePersonDel(id) {
  return request({
    url: 'merchant_backend/staffs/' + id,
    method: 'DELETE'
  })
}

/**
 * 店员资料修改获取
 * @param {Number} id 店员id
 */
export function handleGetPersonInit(id) {
  return request({
    url: '/merchant_backend/staffs/' + id,
    method: 'GET'
  })
}

/**
 * 店员资料修改提交
 * @param {Number} id 店员id
 * @param {Object} date 提交参数
 */
export function handleGetPersonSub(id, date) {
  const data = {
    id,
    store_id: date.editStoreid,
    username: date.editUsername,
    passwd: date.editPasswd,
    staff_name: date.editStaff_name,
    position: date.editPosition,
    status: date.editStatus
  }
  return request({
    url: '/merchant_backend/staffs/' + id,
    method: 'PUT',
    data
  })
}

/**
 * 业绩查询初始化
 */
export function scoreInit() {
  return request({
    url:  '/merchant_backend/score',
    method: 'GET'
  })
}

/**
 * 业绩查询分页
 * @param {Number} page 页码
 * @param {Object} date 查询参数
 */
export function handleScorePage(page, date) {
 return request({
   url:  '/merchant_backend/score',
   method: 'GET',
   params: { page, order_number: date.order_number, store_id: date.store_id, staff_id: date.staff_id, pay_at: { start: date.start, end: date.end }  }
 })
}

/**
 * 业绩查询 搜索
 * @param {Object} date 查询参数
 */
export function handleScoreSearch(date) {
  return request({
    url:  '/merchant_backend/score',
    method: 'GET',
    params: { order_number: date.order_number, store_id: date.store_id, staff_id: date.staff_id, pay_at: { start: date.start, end: date.end } }
  })
}

/**
 * 业绩查询-查看订单详情
 * @param {Number} id 订单id
 */
export function handleScoreOrder(id) {
  return request({
    url:  '/merchant_backend/orders/' + id,
    method: 'GET'
  })
}
